import requests
import json

def sendmsg(msg='',atall=False):
    '''测试机器人发送消息,第一个参数是推送消息内容,第二个参数是否at全员'''
    url = 'https://oapi.dingtalk.com/robot/send?access_token=d40f623264a9dba6af4dcc3a77fef3d21077dcb5981b48d8501130521d3a807f'
    header1 = {'Content-Type': "application/json;charset-utf-8"}
    string_textmsg = {'msgtype': 'text', "text": {"content": msg}, "at":{"isAtAll":atall}}
    string_textmsg = json.dumps(string_textmsg)
    res = requests.post(url, data=string_textmsg, headers=header1)
    print(res.text)

if __name__ == "__main__":
    sendmsg('自动推送消息')